package com.lagou.edu.utils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * Description: DynamicProxyAnnotationUtil.
 *
 * @author Wengy
 * @since JDK 1.8
 * @since 1.0.0
 */
public class DynamicProxyAnnotationUtil {
  
  public static boolean findAnnotationFromProxy(Class<?> cusAnnotation, Object target, Method method) throws NoSuchMethodException {
    Annotation[] annotations = target.getClass().getMethod(method.getName(), method.getParameterTypes()).getAnnotations();
    boolean hasAnnotation = Arrays.stream(annotations).filter(annotation -> {
      return annotation.annotationType().isAssignableFrom(cusAnnotation);
    }).count() > 0;
    return hasAnnotation;
  }
}

